#include"../process.h"
#include"default_model.h"
#include"distance_calc.h"
#include"model/ngram_lm.h"
#include"model/ed_translate_model.h"
#include"model\abbr_model.h"
#include"config.h"
#include"../../log/log_mgr.h"
#include"model\correction_model.h"
#include"graph\graph.h"

void export_model(fstream &out_file, map<string, int> &model)
{
	map<string, int>::iterator itr;
	for(itr = model.begin(); itr != model.end(); ++ itr)
		out_file << (*itr).first << "\t" << (*itr).second << " | ";
	out_file << endl;
}

int main(int argc, const char* argv[])
{
	fstream input(argv[1], fstream::in);
	fstream stop_file(argv[2], fstream::in);
	fstream q2f_file(argv[3], fstream::out);
	fstream lang_file(argv[4], fstream::out);
	fstream trans_file(argv[5], fstream::out);
	fstream abbr_file(argv[6], fstream::out);

	fstream conf_file(argv[7], fstream::in);
	Config::load(&conf_file);
	conf_file.close();
	DistCalc dist_calc;
	NgramLanguageModel lang_model(atoi((Config::get("gram").c_str())));
	EdTranslateModel trans_model(&dist_calc);
	AbbrModel abbr_model(&stop_file);
	stop_file.close();
	CorrectionModel corr_model(&dist_calc);

	util::LogMgr::init(argc, argv);
	util::LogMgr::time_start();
	DefaultModel model(&dist_calc, &lang_model, &trans_model, &abbr_model, &corr_model);

	string line;
	while(!input.eof()){
		getline(input, line);
		model.build(line);
		export_model(trans_file, model.getTransModel());
		export_model(lang_file, model.getLangModel());
		export_model(q2f_file, model.getLogSortCut());
		export_model(abbr_file, model.getAbbrModel());
	}
	util::LogMgr::time_end();
	util::LogMgr::done();
	input.close();
	q2f_file.close();
	lang_file.close();
	trans_file.close();
	return 0;
}
//int main(int argc, const char* argv[])
//{
//	fstream input(argv[1], fstream::in);
//	fstream output(argv[2], fstream::out);
//	util::LogMgr::init(argc, argv);
//	util::LogMgr::time_start();
//	QueryGraph graph(&input);
//	cout << "load done\n";
//	vector<vector<string>> v;
//	graph.flood(v);
//	for(int i = 0 ; i < v.size(); ++ i ){
//		for(int j = 0 ; j < v[i].size(); ++ j)
//			output << v[i][j] << " | ";
//		output << endl;
//	}
//	cout << "flood done\n";
//	input.close();
//	util::LogMgr::time_end();
//	util::LogMgr::done();
//	return 0;
//}